package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZLJ
 * @date 2025/10/9 14:46
 * @Description
 */
@Slf4j
@RestController
@RequestMapping("/activities")
@SuppressWarnings("all")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable Integer type){
        activityService.getByType(type);
        log.info("查询活动类型:{}",type);
        return Result.success(activityService.getByType(type));
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        log.info("查询活动id:{}",id);
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("修改活动:{}",activity);
        activityService.update(activity);
        return Result.success();
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        log.info("新增活动:{}",activity);
        activityService.addActivity(activity);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        log.info("删除活动id:{}",id);
        activityService.deleteById(id);
        return Result.success();
    }

    @GetMapping
    public Result page(@RequestParam(name="channel",required = false) Integer channel,
                       @RequestParam(name="type",required = false) Integer type,
                       @RequestParam(name="status",required = false) Integer status,
                       @RequestParam(name="page",required = true,defaultValue = "1") Integer page,
                       @RequestParam(name="pageSize",required = true,defaultValue = "10") Integer pageSize){
        PageResult<Activity> pageResult = activityService.page(channel,type,status,page,pageSize);
        log.info("分页查询活动,参数:频道={},类型={},状态={},当前页码={},每页大小={}", channel, type, status, page, pageSize);
        return Result.success(pageResult);
    }
}
